package exam.business.service;

import java.util.Date;

import exam.common.constant.ResultPort;
import exam.common.key.KeyStudent;
import exam.common.util.NullCheckUtil;
import exam.model.dao.TStudentDAO;
import exam.model.entity.TStudentEntity;
import exam.system.business.AbstractService;
import exam.system.business.BusinessServiceInfo;

public class StudentUpdateService extends AbstractService {

	// tStudentDAO
	private TStudentDAO tStudentDAO = new TStudentDAO();
	
	@Override
	public String executeService(BusinessServiceInfo serviceInfo)
			throws Exception {
		// TODO Auto-generated method stub
		TStudentEntity tStudentEntity = serviceInfo.getObject(KeyStudent.T_STUDENT_ENTITY);
		if(NullCheckUtil.isNull(tStudentEntity)) {
			return ResultPort.ERROR;
		}
		TStudentEntity tStudentEntityLocal = new TStudentEntity();
		tStudentEntityLocal.setStudentId(tStudentEntity.getStudentId());
		tStudentEntityLocal.setStudentCd(tStudentEntity.getStudentCd());
		tStudentEntityLocal.setFirstName(tStudentEntity.getFirstName());
		tStudentEntityLocal.setLastName(tStudentEntity.getLastName());
		tStudentEntityLocal.setGender(tStudentEntity.getGender());
		tStudentEntityLocal.setBirthday(tStudentEntity.getBirthday());
		tStudentEntityLocal.setCourse(tStudentEntity.getCourse());
		tStudentEntityLocal.setStudentClass(tStudentEntity.getStudentClass());
		tStudentEntityLocal.setUpdateDate(new Date());
		int update = tStudentDAO.updateStudent(tStudentEntityLocal);
		if(update != 0) {
			return ResultPort.SUCCESS;
		} else {
			return ResultPort.NONE;
		}
	}

}
